package com.hzy.quetosys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hzy.quetosys.dao.ProductMapper;
import com.hzy.quetosys.dao.ProductTypeMapper;
import com.hzy.quetosys.entity.Product;
import com.hzy.quetosys.entity.ProductType;
import com.hzy.quetosys.service.ProductService;
import com.hzy.quetosys.service.ProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;

    @Override
    public PageInfo<Product> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        final List<Product> products = productMapper.selectAll();
        PageInfo<Product> pageInfo=new PageInfo<>(products);
        return pageInfo;
    }

    @Override
    public PageInfo<Product> findByKeyword(int pageNum, int pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        List<Product> products=productMapper.selectByKeyword(keyword);
        PageInfo<Product> pageInfo=new PageInfo<>(products);
        return pageInfo;
    }

    @Override
    public Product findById(int id) {
        return productMapper.selectById(id);
    }

    @Override
    public boolean modify(Product product) {
        return productMapper.updateById(product)>0;
    }

    @Override
    public boolean append(Product product) {

            return productMapper.insert(product) > 0;
        }

        @Override
        public boolean remove ( int id){

            return productMapper.deleteById(id) > 0;
        }
    }

